<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane :label="'全部（' + userNum.totalNum + ')'" name="first">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="用户名称" prop="nickName">
            <el-input
                v-model="queryParams.nickName"
                placeholder="请输入用户名称"
                clearable
                @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="userList">
          <el-table-column label="编号" align="center" prop="userId" />
          <el-table-column label="创建时间" align="center" show-overflow-tooltip  prop="createTime" />
          <el-table-column label="用户名称" align="center" prop="nickName" />
          <el-table-column label="联系电话" align="center" prop="phonenumber" />
          <el-table-column label="类型" align="center" prop="">
            <template slot-scope="scope">
              --
            </template>
          </el-table-column>
          <el-table-column label="编写项目" align="center" prop="projectNum" />
          <el-table-column label="消耗Token数量" align="center" prop="">
            <template slot-scope="scope">
              --
            </template>
          </el-table-column>
          <el-table-column label="生成数据专题" align="center" prop="">
            <template slot-scope="scope">
              --
            </template>
          </el-table-column>
          <el-table-column label="状态" align="center" key="status">
            <template slot-scope="scope">
              {{ scope.row.status == '0' ? '启用' : '禁用'}}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="handleView(scope.row)"
                  v-hasPermi="['system:user:query']"
              >查看</el-button>
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  v-if="scope.row.status == '0'"
                  @click="handleStatusChange(scope.row,'1')"
                  v-hasPermi="['system:user:edit']"
              >禁用</el-button>
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  v-if="scope.row.status == '1'"
                  @click="handleStatusChange(scope.row,'0')"
                  v-hasPermi="['system:user:edit']"
              >启用</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
<!--      <el-tab-pane :label="'内部（' + userNum.innerNum + ')'" name="second">-->
<!--        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
<!--          <el-form-item label="用户名称" prop="nickName">-->
<!--            <el-input-->
<!--                v-model="queryParams.nickName"-->
<!--                placeholder="请输入用户名称"-->
<!--                clearable-->
<!--                @keyup.enter.native="handleQuery"-->
<!--            />-->
<!--          </el-form-item>-->
<!--          <el-form-item>-->
<!--            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--          </el-form-item>-->
<!--        </el-form>-->

<!--        <el-table v-loading="loading" :data="innerUserList">-->
<!--&lt;!&ndash;        <el-table v-loading="loading" :data="userList">&ndash;&gt;-->
<!--          <el-table-column label="编号" align="center" prop="userId" />-->
<!--          <el-table-column label="创建时间" align="center" show-overflow-tooltip prop="createTime" />-->
<!--          <el-table-column label="用户名称" align="center" prop="nickName" />-->
<!--          <el-table-column label="联系电话" align="center" prop="phonenumber" />-->
<!--          <el-table-column label="类型" align="center" prop="">-->
<!--            <template slot-scope="scope">-->
<!--              &#45;&#45;-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="编写项目" align="center" prop="projectNum" />-->
<!--          <el-table-column label="消耗Token数量" align="center" prop="">-->
<!--            <template slot-scope="scope">-->
<!--              &#45;&#45;-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="生成数据专题" align="center" prop="">-->
<!--            <template slot-scope="scope">-->
<!--              &#45;&#45;-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="状态" align="center" key="status">-->
<!--            <template slot-scope="scope">-->
<!--              {{ scope.row.status == '0' ? '启用' : '禁用'}}-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">-->
<!--            <template slot-scope="scope">-->
<!--              <el-button-->
<!--                  size="mini"-->
<!--                  type="text"-->
<!--                  icon="el-icon-view"-->
<!--                  @click="handleView(scope.row)"-->
<!--                  v-hasPermi="['system:user:query']"-->
<!--              >查看</el-button>-->
<!--              <el-button-->
<!--                  size="mini"-->
<!--                  type="text"-->
<!--                  icon="el-icon-edit"-->
<!--                  v-if="scope.row.status == '0'"-->
<!--                  @click="handleStatusChange(scope.row,'1')"-->
<!--                  v-hasPermi="['system:user:edit']"-->
<!--              >禁用</el-button>-->
<!--              <el-button-->
<!--                  size="mini"-->
<!--                  type="text"-->
<!--                  icon="el-icon-edit"-->
<!--                  v-if="scope.row.status == '1'"-->
<!--                  @click="handleStatusChange(scope.row,'0')"-->
<!--                  v-hasPermi="['system:user:edit']"-->
<!--              >启用</el-button>-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--        </el-table>-->
<!--      </el-tab-pane>-->
<!--      <el-tab-pane :label="'平台（' + userNum.platformNum + ')'" name="third">-->
<!--        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
<!--          <el-form-item label="用户名称" prop="nickName">-->
<!--            <el-input-->
<!--                v-model="queryParams.nickName"-->
<!--                placeholder="请输入用户名称"-->
<!--                clearable-->
<!--                @keyup.enter.native="handleQuery"-->
<!--            />-->
<!--          </el-form-item>-->
<!--          <el-form-item>-->
<!--            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--          </el-form-item>-->
<!--        </el-form>-->

<!--        <el-table v-loading="loading" :data="platformUserList">-->
<!--&lt;!&ndash;        <el-table v-loading="loading" :data="userList">&ndash;&gt;-->
<!--          <el-table-column label="编号" align="center" prop="userId" />-->
<!--          <el-table-column label="创建时间" align="center" show-overflow-tooltip prop="createTime" />-->
<!--          <el-table-column label="用户名称" align="center" prop="nickName" />-->
<!--          <el-table-column label="联系电话" align="center" prop="phonenumber" />-->
<!--          <el-table-column label="类型" align="center" prop="">-->
<!--            <template slot-scope="scope">-->
<!--              &#45;&#45;-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="编写项目" align="center" prop="projectNum" />-->
<!--          <el-table-column label="消耗Token数量" align="center" prop="">-->
<!--            <template slot-scope="scope">-->
<!--              &#45;&#45;-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="生成数据专题" align="center" prop="">-->
<!--            <template slot-scope="scope">-->
<!--              &#45;&#45;-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="状态" align="center" key="status">-->
<!--            <template slot-scope="scope">-->
<!--              {{ scope.row.status == '0' ? '启用' : '禁用'}}-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">-->
<!--            <template slot-scope="scope">-->
<!--              <el-button-->
<!--                  size="mini"-->
<!--                  type="text"-->
<!--                  icon="el-icon-view"-->
<!--                  @click="handleView(scope.row)"-->
<!--                  v-hasPermi="['system:user:query']"-->
<!--              >查看</el-button>-->
<!--              <el-button-->
<!--                  size="mini"-->
<!--                  type="text"-->
<!--                  icon="el-icon-edit"-->
<!--                  v-if="scope.row.status == '0'"-->
<!--                  @click="handleStatusChange(scope.row,'1')"-->
<!--                  v-hasPermi="['system:user:edit']"-->
<!--              >禁用</el-button>-->
<!--              <el-button-->
<!--                  size="mini"-->
<!--                  type="text"-->
<!--                  icon="el-icon-edit"-->
<!--                  v-if="scope.row.status == '1'"-->
<!--                  @click="handleStatusChange(scope.row,'0')"-->
<!--                  v-hasPermi="['system:user:edit']"-->
<!--              >启用</el-button>-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--        </el-table>-->
<!--      </el-tab-pane>-->
    </el-tabs>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户配置对话框 -->
    <el-dialog title="查看用户信息" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="userForm" :model="userForm" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="编号" prop="userId">
              <el-input v-model="userForm.userId" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户名称" prop="nickName">
              <el-input v-model="userForm.nickName" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phonenumber">
              <el-input v-model="userForm.phonenumber" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="类型" prop="">
              <el-input disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="编写项目" prop="projectNum">
              <el-input v-model="userForm.projectNum" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-input v-model="userForm.status === '0' ? '启用' : '禁用' " disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="创建时间" prop="createTime">
              <el-input v-model="userForm.createTime" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { pageUser,changeUserStatus } from "@/api/system/user"
import Treeselect from "@riophae/vue-treeselect";

export default {
  name: "ProjectUser",
  components: {Treeselect},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息表格数据
      platformUserList: [],
      innerUserList: [],
      userList: [],
      userNum: {
        totalNum: 0,
        innerNum: 0,
        platformNum: 0
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickName: null
      },
      // 表单参数
      userForm: {},
      // 表单校验
      activeName: 'first'
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 用户状态修改
    handleStatusChange(row,status) {
      let text = status === "0" ? "启用" : "禁用"
      this.$modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗？').then(function() {
        return changeUserStatus(row.userId, status)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess(text + "成功")
      }).catch(function() {
      })
    },
    handleView(row) {
      this.open = true
      this.userForm = row
    },
    handleClick(tab, event) {
      if(this.activeName == 'first') {
        this.getList()
      } else if (this.activeName == 'second') {

      } else if (this.activeName == 'third') {
      }
    },
    /** 查询白皮书基本信息列表 */
    getList() {
      this.loading = true
      pageUser(this.queryParams).then(response => {
        this.userList = response.rows
        this.total = response.total
        this.userNum.totalNum = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    }
  }
}
</script>
